package com.mac.intellect_flow.admin.controller.flowable;


import com.mac.intellect_flow.flowable.model.vo.FlowTaskVo;
import com.mac.intellect_flow.flowable.service.FlowInstanceService;
import com.mac.intellect_flow.reply.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 工作流流程实例管理
 *
 * @author mac
 */
@Slf4j
@Tag(name = "工作流流程实例管理")
@RestController
@RequestMapping("/flowable/instance")
public class FlowInstanceController {

    @Autowired
    private FlowInstanceService flowInstanceService;


    @Operation(summary = "激活或挂起流程实例")
    @PostMapping(value = "/updateState")
    public R updateState(@Parameter(name = "1:激活,2:挂起", required = true) @RequestParam Integer state,
                                  @Parameter(name = "流程实例ID", required = true) @RequestParam String instanceId) {
        flowInstanceService.updateState(state,instanceId);
        return R.success();
    }

    @Operation(summary = "删除流程实例")
    @DeleteMapping(value = "/delete/{instanceIds}")
    public R delete(@Parameter(name = "流程实例ID", required = true) @PathVariable String[] instanceIds,
                    @Parameter(name = "删除原因") @RequestParam(required = false) String deleteReason) {
        for (String instanceId : instanceIds) {
            flowInstanceService.delete(instanceId,deleteReason);
        }
        return R.success();
    }
}
